﻿using System;
using System.Collections.Generic;
using System.Text;

namespace voidbox
{
    public struct Color32
    {
        public byte r;
        public byte g;
        public byte b;
        public byte a;
        public Color32(byte _R, byte _G, byte _B, byte _A = 255)
        {
            r = _R;
            g = _G;
            b = _B;
            a = _A;
        }
        public static Color32 FromColorNum(uint num)
        {
            var a = num & 0xff;
            var r = num >> 8 & 0xff;
            var g = num >> 16 & 0xff;
            var b = num >> 24 & 0xff;
            return new Color32((byte)r, (byte)g, (byte)b, (byte)a);

        }
        public static Color32 White
        {
            get
            {
                return new Color32(255, 255, 255, 255);
            }
        }

        // 从 Color 隐式转换到 Color32
        public static implicit operator Color32(Color color)
        {
            return new Color32(
                (byte)(color.r * 255),
                (byte)(color.g * 255),
                (byte)(color.b * 255),
                (byte)(color.a * 255)
            );
        }

        // 从 Color32 隐式转换到 Color
        public static implicit operator Color(Color32 color32)
        {
            return new Color(
                color32.r / 255.0f,
                color32.g / 255.0f,
                color32.b / 255.0f,
                color32.a / 255.0f
            );
        }
    }
}